﻿Imports System.Data.Odbc

Public Class clsSzukaniePakowania

#Region "Attributes"

    Dim mvarOpakowania As New DataTable("Pakowanie")

#End Region

#Region "Properties"

    Public Property Opakowanie() As DataTable
        Get
            Return mvarOpakowania
        End Get
        Set(ByVal value As DataTable)
            mvarOpakowania = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()

        UtworzTabele()

    End Sub

    Private Sub UtworzTabele()

        With mvarOpakowania.Columns
            .Add("id_pakowania", GetType(String))
            .Add("nazwa", GetType(String))
        End With

    End Sub

    Public Sub Szukaj(ByVal lvarDbHolder As clsDataBase, ByRef ErrorHandler As clsErrorHandler, ByVal Zapytanie As String)

        Dim lvarNewRow As DataRow
        Dim lvarReader As OdbcDataReader = Nothing

        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_pakowanie", 1, VAR_ERROR_HANDLER)
            '(lvarDbHolder, "SELECT pakowanie.id, pakowanie.nazwa FROM oem.pakowanie " & lvarZapytanie & " order by pakowanie.nazwa;", VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    lvarNewRow = mvarOpakowania.NewRow()
                    With lvarNewRow
                        .Item("id_pakowania") = IIf(IsDBNull(lvarReader.Item("id")), "", lvarReader.Item("id"))
                        .Item("nazwa") = IIf(IsDBNull(lvarReader.Item("nazwa")), "", lvarReader.Item("nazwa"))
                    End With
                    mvarOpakowania.Rows.Add(lvarNewRow)
                End While
            End If
        End If

    End Sub

#End Region

End Class

